let webpack = require('webpack')
let webpackStream = require('webpack-stream')
let webpackDevMiddleware = require('webpack-dev-middleware')
let webpackHotMiddleware = require('webpack-hot-middleware')

module.exports = (ispod, gulp, $, server, mem) => {
    let webpackConfig = require('../../webpack')(ispod)
    gulp.task('dev:bower', ['bower:build'], done => {
        const bundler = webpack(webpackConfig)
        server.init({
            notify: false,
            logLevel: 'none',
            server: {
                baseDir: 'dist',
                middleware: [
                    webpackDevMiddleware(bundler, webpackConfig.devServer),
                    webpackHotMiddleware(bundler)
                ]
            }
        }, done)
    })
    gulp.task('build:bower', () => {
        return gulp.src('src/js/app.js')
            .pipe(webpackStream(webpackConfig, webpack))
            .pipe(mem.dest('dist/js'))
    })
    gulp.task('run:bower', () => {
        return gulp.src('src/js/app.js')
            .pipe(webpackStream(webpackConfig, webpack))
            .pipe(mem.dest('dist/js'))
    })
    gulp.task('ana:bower', () => {
        return gulp.src('src/js/app.js')
            .pipe(webpackStream(webpackConfig, webpack))
            .pipe(mem.dest('dist/js'))
    })
}
